package com.zxy.salenet.web.mapper;

import com.zxy.salenet.web.pojo.SalenetComm;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

 /**
   *  SalenetCommMapper。
     */
public interface SalenetCommMapper extends Mapper<SalenetComm> {

    /**
     * 获取当前使用的地址
     * @param userComm
     * @return
     */
    @Select(value = "SELECT * FROM salenet_comm WHERE id=#{userComm}")
    SalenetComm selectCurrComm(@Param("userComm") Integer userComm);

    /**
     * 获取地址列表
     * @param userId
     * @return
     */
    @Select(value = "SELECT * FROM salenet_comm WHERE comm_user_id = #{userId}")
    List<SalenetComm> selectAllByUserId(@Param("userId") Integer userId);

    /**
     * 添加常用地址
     * @param salenetComm
     * @return
     */
    @Insert(value = "INSERT INTO salenet_comm VALUES(default,#{commUserId},#{commProvince},#{commCity},#{commCounty},#{commVillage},#{commAddress},#{commUsername},#{commPhone})")
    Integer insertCommById(SalenetComm salenetComm);

    /**
     * 根据sid删除对应的地址
     * @param sid
     * @return
     */
    @Delete(value = "DELETE FROM salenet_comm WHERE id = #{sid}")
    Integer deleteCommById(@Param("sid") Integer sid);

    @Select("select * from salenet_comm where id = #{id}")
    SalenetComm selectCommById(@Param("id") Integer id);
}